package com.example.chenjian.myapplication;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by chenjian on 2017/1/6.
 */

public class GoodsListFragment extends Fragment {
    private ListView mGoodsListView;
    private List<GoodsItem> mGoodsList;
    private GoodsListAdapter mAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        initData();
        View view = inflater.inflate(R.layout.goods_list_fragment, null);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        mGoodsListView = (ListView) getView().findViewById(R.id.goods_list);
        mAdapter = new GoodsListAdapter(getActivity(), R.layout.goods_list_item, mGoodsList);
        mGoodsListView.setAdapter(mAdapter);
    }

    private void initData() {
        mGoodsList = new ArrayList<GoodsItem>();
        for (int i = 0; i < 20; ++i){
            GoodsItem item = new GoodsItem("我是第" + i+ "个商品", "", i * 10.0f, "优惠多多，折扣多多", "");
            mGoodsList.add(item);
        }
    }
}
